package com.rabbitmq.demo.mqcluster;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile(value="cluster")
@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue queue(){
        return new Queue("cluster.queue");
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("cluster.direct.exchange");
    }

    public Binding binding(){
        return BindingBuilder.bind(queue()).to(directExchange()).withQueueName();
    }

    @Profile(value="sender")
    @Bean
    public Sender sender(){
        return new Sender();
    }

    @Profile(value="receiver")
    @Bean
    public Receiver receiver(){
        return new Receiver();
    }
}
